package fjut.acm.coding.controller;

import fjut.acm.coding.component.token.TokenManager;
import fjut.acm.coding.component.token.TokenModel;
import fjut.acm.coding.config.interceptor.CaptchaRequired.CaptchaRequired;
import fjut.acm.coding.config.interceptor.LoginRequired.LoginRequired;
import fjut.acm.coding.entity.result.ResultJson;
import fjut.acm.coding.service.TestService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/Test")
@CrossOrigin
public class TestController {

    @Resource
    TestService testService;

    @Resource
    TokenManager tokenManager;

    @GetMapping("/MyTest1")
    public ResultJson MyTest1(){
        ResultJson resultJson = new ResultJson();
        resultJson.addInfo(testService.myTest());
        return resultJson;
    }

    // 异常处理测试
    @GetMapping("/MyTest2")
    public ResultJson MyTest2(){
        ResultJson resultJson = new ResultJson();
        int n = 10/0;
        return resultJson;
    }

    // 返回一个token
    @GetMapping("/MyTest3")
    public ResultJson MyTest3(){
        ResultJson resultJson = new ResultJson();

        TokenModel model = new TokenModel();
        model.setIp("10.20.60.43");
        model.setRole("游客");
        model.setUsername("18780802571");
        String token = tokenManager.createToken(model);

        resultJson.addInfo(token);
        return resultJson;
    }


    // jwt测试
    @GetMapping("/MyTest4")
    @LoginRequired
    public ResultJson MyTest4(){
        ResultJson resultJson = new ResultJson();



        return resultJson;
    }

    // 验证码测试
    @GetMapping("/MyTest5")
    @CaptchaRequired
    public ResultJson MyTest5(){
        ResultJson resultJson = new ResultJson();
        return resultJson;
    }
}
